//数据获取
$(() => {
  let tableView = {
    enterStorage: $(".enterStorageMaster-view"),
    purchase: $(".purchase-view")
  };
  var typeTest;
  //分页
  var page = 1;
  //分页，右边
  $(".chr-enterStorageMaster").on("click", function() {
    $($(".enterStorageMaster-view").children()[0]).remove();
    page = page + 1;
    //清空
    // tableView.enterStorage.remove();
    let tableView = {
      enterStorage: $(".enterStorageMaster-view"),
      purchase: $(".purchase-view")
    };
    $.ajax({
      url:
        "http://www.fjemiot.cn/erp/enterStorage?pageNum=" +
        page +
        "&pageSize=5&type=0",
      success: reply => {
        tableView.enterStorage.append(tablegen(reply.value));
        console.log(reply.value);
        typeTest = reply.value[0].type;
        console.log("type" + typeTest);
      },
      error: reply => {
        tip.alert("获取信息失败", "采购订单列表", "error", 1500);
      }
    });
  });
  //左边
  $(".chl-enterStorageMaster").on("click", function() {
    $($(".enterStorageMaster-view").children()[0]).remove();

    // tableView.enterStorage.remove();
    let tableView = {
      enterStorage: $(".enterStorageMaster-view"),
      purchase: $(".purchase-view")
    };
    page = page - 1;
    $.ajax({
      url:
        "http://www.fjemiot.cn/erp/enterStorage?pageNum=" +
        page +
        "&pageSize=5&type=0",
      success: reply => {
        tableView.enterStorage.append(tablegen(reply.value));
        console.log(reply.value);
        typeTest = reply.value[0].type;
        console.log("type" + typeTest);
      },
      error: reply => {
        tip.alert("获取信息失败", "采购订单列表", "error", 1500);
      }
    });
  });
  //添加操作
  $(() => {
    let $entry = {
      user: $(".user-button"),
      menu: $(".entry-menu"),
      show: $(".right-contain"),
      form: $(".form-area")
    };
    $entry.show.on("click", e => {
      if (e.target.tagName === "BUTTON") {
        let addPattern = /^add-/,
          btnClass = e.target.classList.item(0); //当前按钮的类名
        // console.log(checkPattern.test(btnClass));

        if (btnClass == "add-enterStorage") {
          console.log(
            $(".add-enterStorage").parents()[4].firstElementChild.classList[1]
          );
          let page = btnClass.split("-")[1];
          //把input的值去掉
          $(".enterStorageL150").val("");
          $entry.form
            .find(".enterStorage")
            .removeClass("hide")
            .addClass("show")
            .addClass(page + "-slide-down");
        }
      }
    });
    $entry.form.on("click", e => {
      if (e.target.tagName === "BUTTON") {
        btnClass = e.target.classList.item(0);
        console.log(btnClass);
        if (btnClass == "enterStorage-submit") {
          $(".enterStorage")
            .removeClass("show")
            .addClass("hide");
        } else if (btnClass == "enterStorage-back") {
          //关闭
          $(".enterStorage")
            .removeClass("show")
            .addClass("hide");
          //清空input
          $(".enterStorage .i1501").val("");
          $(".enterStorage .i1502").val("");
          $(".enterStorage .i1503").val("");
          $(".enterStorage .i1504").val("");
          $(".enterStorage .enterStorageL150").val("");
        }
      }
    });

    //点击选择采购单的时候

    //对采购主表，返回
    $(".purchase-back").on("click", function() {
      //关闭主表
      $(".purchase")
        .removeClass("show")
        .addClass("hide")
        .addClass("purchase" + "-slide-down");
    });

    // 对采购详细表进行选择
    $(() => {
      var purchaseDetails = new Array(); //暂存选中的产品
      let tableView = {
        purchaseDetails: $(".purchaseDetailsenterStorage-view"),
        purchaseDetailsenterStorage: $(".purchaseDetailsenterStorage-view2")
      };
      //点击选择，打开
      $(".orde-noi150").on("click", function() {
        //清空表格，选中的表格
        tableView.purchaseDetailsenterStorage.html(tablegen());
        $(".purchase")
          .removeClass("hide")
          .addClass("show")
          .addClass("purchase" + "-slide-down");
      });

      //对采购主表进行选择
      $(".firstPurchase ").on("click", "tr", function() {
        console.log(typeof $(this).index());
        if ($(this).index() != 0) {
          purchaseDetails = []; //清空
          // console.log(this);
          var a = $(this)
            .find("td:first")
            .text();
          console.log(a);
          a = parseInt(a);
          //将拿到的订单号拿来请求详细信息
          $(".enterStorage .enterStorageL150").val(a); //赋值给input
          //赋值
          tableView.purchaseDetails.html(tablegen());
          $.ajax({
            url: "http://www.fjemiot.cn/erp/purchaseDetail/4/8/" + a,
            success: reply => {
              // 对数据解析
              for (var i = 0; i < reply.value.length; i++) {
                reply.value[i].productNo = reply.value[i].product.productNo;
                reply.value[i].brand = reply.value[i].product.brand;
                reply.value[i].type = reply.value[i].product.type;
                reply.value[i].gWeight = reply.value[i].product.gWeight;
                reply.value[i].standard = reply.value[i].product.standard;
                reply.value[i].level = reply.value[i].product.level;
                reply.value[i].unit = reply.value[i].product.unit;
                reply.value[i].cost = reply.value[i].product.cost;
                reply.value[i].price = reply.value[i].product.price;
                delete reply.value[i].product;
              }
              tableView.purchaseDetails.append(tablegen(reply.value));
              console.log(reply.value);
            },
            error: reply => {
              tip.alert("获取信息失败", "采购订单列表", "error", 1500);
            }
          });
          //关闭采购主表
          $(".purchase")
            .removeClass("show")
            .addClass("hide")
            .addClass("purchase" + "-slide-down");
          // 打开采购详细表
          $(".purchaseDetails")
            .removeClass("hide")
            .addClass("show")
            .addClass("purchaseDetails" + "-slide-down");
        }
      });

      //采购详细表
      $(".purchaseDetailsenterStorage-view").on("click", "tr", function() {
        console.log("点击了");
        console.log(this);
        var td = $(this).find("td");
        const temp = {
          orderNo: "",
          number: "",
          price: "",
          productNo: "",
          brand: "",
          type: "",
          gWeight: "",
          standard: "",
          level: "",
          unit: "",
          cost: ""
        };
        temp.orderNo = td.eq(0).html();
        temp.number = td.eq(1).html();
        temp.price = td.eq(2).html();
        temp.productNo = td.eq(3).html();
        temp.brand = td.eq(4).html();
        temp.type = td.eq(5).html();
        temp.gWeight = td.eq(6).html();
        temp.standard = td.eq(7).html();
        temp.level = td.eq(8).html();
        temp.unit = td.eq(9).html();
        temp.cost = td.eq(10).html();
        if ($(this).index() != 0) {
          purchaseDetails.push(temp);
          this.remove();
        }
      });
      // 采购详细点击返回
      $(".purchaseDetails-back").on("click", function() {
        //渲染以及打开div
        tableView.purchaseDetailsenterStorage.html(tablegen());
        tableView.purchaseDetailsenterStorage.append(tablegen(purchaseDetails));
        $(".purchaseDetailsenterStorageDiv")
          .removeClass("hide")
          .addClass("show");
        $(".enterStorage-submit")
          .removeClass("hide")
          .addClass("show");
        //关闭主表
        $(".purchaseDetails")
          .removeClass("show")
          .addClass("hide");
        console.log(purchaseDetails);
      });
    });

    //点击菜单显示对应内容
    $(() => {
      $(".base-menu").on("click", "li", function() {
        //将原本选中的菜单项取消选中
        $(".select").removeClass("select");
        //使点击的菜单项被选中
        $(this).addClass("select");
        //将目前显示的内容块隐藏
        $(".right-contain .show")
          .removeClass("show")
          .addClass("hide");
        //找到相应的内容块，将它显示
        $(".right-contain .hide").each((index, tag) => {
          if (
            $(this).text() ==
            $(tag)
              .find(".title")
              .text()
          ) {
            $(tag)
              .removeClass("hide")
              .addClass("show");
          }
        });
      });
    });
  });

  //对表格进行操作
  $(() => {
    let tableView = {
      MasterenterStorage: $(".MasterenterStorage-view"),
      detailsenterStorage: $(".detailsenterStorage-view"),
      employee: $(".employee-view")
    };
    var detailsenterStorageValue = new Array();
    //点击选择雇员
    $(".employee-noi150").on("click", function() {
      console.log("执行啊啊啊");
      $(".employee")
        .removeClass("hide")
        .addClass("show");
      //使用接口拿到雇员
      $.ajax({
        url: "http://www.fjemiot.cn/erp/employees?pageNum=1&pageSize=10",
        type: "get",
        success: reply => {
          tableView.employee.html(tablegen());
          tableView.employee.append(tablegen(reply.employees));
          console.log(reply);
          tip.alert("获取成功", "验货员", "success", 1500);
        },
        error: reply => {
          console.log(reply);
          tip.alert("获取失败", "验货员", "error", 1500);
        }
      });
      //点击某一条雇员
      $(".employee-view").on("click", "tr", function() {
        $(".employee")
          .removeClass("show")
          .addClass("hide");
        //拿到当前点击的雇员号
        var employeeNo = $(this)
          .find("td")
          .eq(0)
          .html();
        console.log(employeeNo);

        console.log("找到雇员" + employeeNo);
        //赋值给对应的input
        $(".enterStorage .i1504").val(employeeNo);
      });
    });
    //点击雇员里面的返回
    $(".employee-back").on("click", function() {
      $(".employee")
        .removeClass("show")
        .addClass("hide");
    });
    //进仓主表
    $(".enterStorageMaster-view").on("click", "tr", function() {
      // 拿到当前tr的type
      console.log("打印");
      var td = $(this).find("td");
      var type66 = td.eq(6).html();
      // console.log("type66:" + td.eq(6).html());

      $(".select-tr").removeClass("select-tr");
      $(this).addClass("select-tr"); //加上背景色
      //点击修改
      $(".upd-MasterenterStorage").on("click", function() {
        console.log(td.eq(0).html());
        //拿到这一行的数据
        console.log(td.eq(0).html());
        a = td.eq(2).html();
        console.log(a);
        //将数据赋值给input
        $(".MasterenterStorage .i1501").val(td.eq(2).html()); //赋值给车号
        $(".MasterenterStorage .i1502").val(td.eq(0).html()); //赋值给日期
        $(".MasterenterStorage .i1503").val(td.eq(5).html()); //赋值给验货员
      });
      //点击修改进仓主表，修改中的提交
      $(".MasterenterStorage-submit").on("click", function() {
        //拿到表中修改的数据
        var carNo = $(".MasterenterStorage .i1501").val();
        var date = $(".MasterenterStorage .i1502").val();
        var employeeNo = parseInt($(".MasterenterStorage .i1503").val());
        //修改页面中的数值
        console.log("修改页面中的数值");
        console.log(td.eq(0).html());
        td.eq(2).text(carNo);
        td.eq(0).text(date);
        td.eq(5).text(employeeNo);

        //拿到剩余数据
        var entryStorageNo = parseInt(td.eq(4).html());
        var orderNo = parseInt(td.eq(1).html());
        var state = parseInt(td.eq(3).html());
        var datetest = {
          carNo: carNo,
          date: date,
          employeeNo: employeeNo,
          entryStorageNo: entryStorageNo,
          orderNo: orderNo,
          state: state
        };
        console.log(JSON.stringify(datetest));
        //执行进仓主表修改
        $.ajax({
          url: "http://www.fjemiot.cn/erp/enterStorage",
          type: "put",
          data: JSON.stringify(datetest),
          contentType: "text/plain",
          // contentType: "application/json",

          success: reply => {
            console.log(reply);
            // tip.alert("修改成功", "进仓主表", "success", 1500);
            return;
            tip.alert("修改失败", "进仓列表", "error", 1500);
          },
          error: reply => {
            console.log(reply);
            tip.alert("修改成功", "进仓主表", "success", 1500);
            // tip.alert("修改失败", "进仓列表", "error", 1500);
            return;
          }
        });
      });
      //点击删除中的确认删除
      $(".delenterStorage-submit").on("click", function() {
        //选中一条并点击删除delenterStorage-submit
        // var enterStorageNo = $(this)
        //   .find("td:first")
        //   .text();

        console.log("确认删除");
        console.log(td);
        var enterStorageNo = td.eq(4).html();
        if (enterStorageNo != "") {
          // 执行删除;
          $.ajax({
            url: "http://www.fjemiot.cn/erp/enterStorage/" + enterStorageNo,
            type: "delete",
            contentType: "text/plain",
            success: reply => {
              console.log(reply);
              tip.alert("删除成功", "进仓主表", "success", 1500);
              td.remove();
            },
            error: reply => {
              tip.alert("删除失败", "进仓列表", "error", 1500);
            }
          });
        } else {
          tip.alert("请选择要删除的进仓单", "删除", "warn");
        }
        $(".delenterStorage")
          .removeClass("show")
          .addClass("hide");
      });

      //点击按钮
      let $entry = {
        user: $(".user-button"),
        menu: $(".entry-menu"),
        show: $(".right-contain"),
        form: $(".form-area")
      };
      //选中点击按钮
      $entry.show.on("click", e => {
        if (e.target.tagName === "BUTTON") {
          btnClass = e.target.classList.item(0); //当前按钮的类名
          if (btnClass == "upd-MasterenterStorage") {
            //选中一条主表并点击修改
            //展开
            $(".MasterenterStorage")
              .removeClass("hide")
              .addClass("show");
          } else if (btnClass == "look-detailsenterStorage") {
            //选中一条进行查看
            $(".detailsenterStorage") //展开
              .removeClass("hide")
              .addClass("show");
            //拿到这一行的主表数据并渲染
            //把这一行存起来
            const temps = [];
            const temp = {
              date: "",
              orderNo: "",
              carNo: "",
              state: "",
              entryStorageNo: "",
              employeeNo: "",
              type: ""
            };
            temp.date = td.eq(0).html();
            temp.orderNo = td.eq(1).html();
            temp.carNo = td.eq(2).html();
            temp.state = td.eq(3).html();
            temp.entryStorageNo = td.eq(4).html();
            temp.employeeNo = td.eq(5).html();
            temp.type = td.eq(6).html();
            temps.push(temp);
            console.log("进仓主表的一条数据");
            console.log(temps);
            console.log("这是编号");
            console.log(type66);
            // console.log(parseInt(td.eq(4).html()));
            tableView.MasterenterStorage.html(tablegen());
            //渲染表格http://www.fjemiot.cn/erp/enterStorageDetail/1/5/4
            tableView.MasterenterStorage.append(tablegen(temps));
            //拿到进仓详细表http://www.fjemiot.cn/erp/enterStorageDetail/1/5/4
            $.ajax({
              url:
                "http://www.fjemiot.cn/erp/enterStorageDetail/3/4/" +
                parseInt(td.eq(4).html()),
              success: reply => {
                console.log(reply);
                //解析数据
                for (var i = 0; i < reply.value.length; i++) {
                  reply.value[i].productNo = reply.value[i].product.productNo;
                  reply.value[i].brand = reply.value[i].product.brand;
                  reply.value[i].type = reply.value[i].product.type;
                  reply.value[i].gWeight = reply.value[i].product.gWeight;
                  reply.value[i].standard = reply.value[i].product.standard;
                  reply.value[i].level = reply.value[i].product.level;
                  reply.value[i].unit = reply.value[i].product.unit;
                  reply.value[i].cost = reply.value[i].product.cost;
                  reply.value[i].price = reply.value[i].product.price;
                  delete reply.value[i].product;
                  delete reply.value[i].entryStorageNo;
                }
                var test = [];
                tableView.detailsenterStorage.html(tablegen(test));
                // detailsenterStorageValue = reply.value;
                tableView.detailsenterStorage.append(tablegen(reply.value));
                console.log("哈哈哈");
                console.log(reply.value.length);
                if (reply.value.length == 0) {
                  tip.alert("该进仓单没有详细信息", "进仓单", "warn", 1500);
                }
              },
              error: reply => {
                tip.alert("获取信息失败", "进仓单", "error", 1500);
              }
            });
          } else if (btnClass == "check-checkenterStorage") {
            //选中一条并点击审核通过
            $(".checkenterStorage")
              .removeClass("hide")
              .addClass("show");
          } else if (btnClass == "del-delenterStorage") {
            //选中一条并点击删除
            $(".delenterStorage")
              .removeClass("hide")
              .addClass("show");
          } else if (btnClass == "working-checkenterStorage") {
            $(".workingenterStorage")
              .addClass("show")
              .removeClass("hide");
          }
        }
      });

      //点击按钮之后展开
      $entry.form.on("click", e => {
        if (e.target.tagName === "BUTTON") {
          btnClass = e.target.classList.item(0); //当前按钮的类名
          if (btnClass == "MasterenterStorage-back") {
            //选中一条主表并点击修改，之后点击返回
            $(".MasterenterStorage")
              .removeClass("show")
              .addClass("hide");
          } else if (btnClass == "MasterenterStorage-submit") {
            //选中一条主表并点击修改
            $(".MasterenterStorage")
              .removeClass("show")
              .addClass("hide");
          } else if (btnClass == "detailsenterStorage-back") {
            console.log();
            //选中一条明细并点击返回
            $(".detailsenterStorage")
              .removeClass("show")
              .addClass("hide");
          } else if (btnClass == "detailsenterStorage-submit") {
            //选中一条明细修改，并点击修改
            // 弹框
            $(".detailsEditenterStorage")
              .removeClass("hide")
              .addClass("show");
          } else if (btnClass == "workingenterStorage-submit") {
            //选中一条并点击执行
            var type = parseInt(
              $(this)
                .find("td")
                .eq(8)
                .html()
            );
            var state = parseInt(
              $(this)
                .find("td")
                .eq(3)
                .html()
            );
            console.log("审核3" + state);
            if (state == 1) {
              var entryStorageNo = parseInt(
                $(this)
                  .find("td")
                  .eq(6)
                  .html()
              );

              var dataTest = {
                entryStorageNo: entryStorageNo,
                state: 2,
                type: type
              };
              console.log(JSON.stringify(dataTest));
              $.ajax({
                url: "http://www.fjemiot.cn/erp/enterStorage",
                type: "put",
                data: JSON.stringify(dataTest),
                // contentType: "text/plain",
                contentType: "application/json",
                success: reply => {
                  console.log(reply);
                  tip.alert("执行成功", "进仓主表", "success", 1500);
                },
                error: reply => {
                  console.log(reply);
                  tip.alert("执行失败", "进仓列表", "error", 1500);
                }
              });
            } else {
              tip.alert("该条进仓主表不能执行", "进仓列表", "warn", 1500);
            }

            $(".workingenterStorage")
              .addClass("hide")
              .removeClass("show");
          } else if (btnClass == "checkenterStorage-submit") {
            //执行审核通过
            //选中一条并点击审核
            var type = parseInt(
              $(this)
                .find("td")
                .eq(8)
                .html()
            );
            var state = parseInt(
              $(this)
                .find("td")
                .eq(3)
                .html()
            );
            console.log("审核" + state);
            if (state == 1 || state == 2) {
              tip.alert("该条进仓主表已审核", "进仓列表", "warn", 1500);
            } else {
              var entryStorageNo = parseInt(
                $(this)
                  .find("td")
                  .eq(6)
                  .html()
              );

              var dataTest = {
                entryStorageNo: entryStorageNo,
                state: 1,
                type: type
              };
              console.log(JSON.stringify(dataTest));
              $.ajax({
                url: "http://www.fjemiot.cn/erp/enterStorage",
                type: "put",
                data: JSON.stringify(dataTest),
                // contentType: "text/plain",
                contentType: "application/json",
                success: reply => {
                  console.log(reply);
                  tip.alert("审核成功", "进仓主表", "success", 1500);
                },
                error: reply => {
                  console.log(reply);
                  tip.alert("审核失败", "进仓列表", "error", 1500);
                }
              });
            }

            $(".checkenterStorage")
              .removeClass("show")
              .addClass("hide");
          } else if (btnClass == "checkenterStorage2-submit") {
            //使用接口
            //选中一条并点击审核不通过
            var type = parseInt(
              $(this)
                .find("td")
                .eq(8)
                .html()
            );
            var state = parseInt(
              $(this)
                .find("td")
                .eq(3)
                .html()
            );
            console.log("审核" + state);
            if (state == 1 || state == 2) {
              tip.alert("该条进仓主表已审核", "进仓列表", "warn", 1500);
            } else {
              var entryStorageNo = parseInt(
                $(this)
                  .find("td")
                  .eq(6)
                  .html()
              );

              var dataTest = {
                entryStorageNo: entryStorageNo,
                state: -1,
                type: type
              };
              console.log(JSON.stringify(dataTest));
              $.ajax({
                url: "http://www.fjemiot.cn/erp/enterStorage",
                type: "put",
                data: JSON.stringify(dataTest),
                // contentType: "text/plain",
                contentType: "application/json",
                success: reply => {
                  console.log(reply);
                  tip.alert("审核成功", "进仓主表", "success", 1500);
                },
                error: reply => {
                  console.log(reply);
                  tip.alert("审核失败", "进仓列表", "error", 1500);
                }
              });
            }

            $(".checkenterStorage")
              .removeClass("show")
              .addClass("hide");
          } else if (btnClass == "delenterStorage-back") {
            // console.log("删除的返回");
            $(".delenterStorage")
              .removeClass("show")
              .addClass("hide");
          } else if (btnClass == "detailsEditenterStorage-submit") {
            //获得数据并使用接口--->进仓明细表的修改
            var td = tableView.detailsenterStorage.children().find("tr");
            var number = $(".detailsEditenterStorage .i1501").val();
            number = parseInt(number);
            // console.log(typeof number);
            var position = $(".detailsEditenterStorage .i1502").val();

            var uniqueNo = $(".detailsEditenterStorage .i1503").val();

            var entryStorageNo = String(
              td
                .find("td")
                .eq(0)
                .html()
            );
            var productNo = String(
              td
                .find("td")
                .eq(4)
                .html()
            );
            var dateTest = {
              entryStorageNo: entryStorageNo,
              number: number,
              position: position,
              product: {
                productNo: productNo
              },
              uniqueNo: uniqueNo
            };
            console.log(JSON.stringify(dateTest));
            //执行进仓明细表的修改
            $.ajax({
              url: "http://www.fjemiot.cn/erp/enterStorageDetail",
              type: "put",
              data: JSON.stringify(dateTest),
              contentType: "application/json",
              // contentType: "text/plain",
              success: reply => {
                console.log(reply);
                tip.alert("修改成功", "进仓明细表", "success", 1500);
              },
              error: reply => {
                tip.alert("修改失败", "进仓明细表", "error", 1500);
              }
            });

            $(".detailsEditenterStorage")
              .removeClass("show")
              .addClass("hide");
          } else if (btnClass == "checkenterStorage-back") {
            //审核中的返回,消失
            $(".checkenterStorage")
              .removeClass("show")
              .addClass("hide");
          } else if (btnClass == "workingenterStorage-back") {
            $(".workingenterStorage")
              .addClass("hide")
              .removeClass("show");
          }
        }
      });

      //点击提交--->添加进仓单
      $(".enterStorage-submit").on("click", function() {
        //获得全部表单
        var carNo = $(".enterStorage .i1501").val();
        var date = $(".enterStorage .i1502").val();
        var position = $(".enterStorage .i1503").val();
        var employeeNo = parseInt($(".enterStorage .i1504").val());
        var orderNo = parseInt($(".enterStorage .enterStorageL150").val());
        // var type=
        console.log("提交啦" + carNo, date, employeeNo, orderNo);

        //生成件号用的
        var date2 = new Date(date); //就是这么简单
        var month = date2.getMonth() + 1;
        var day = date2.getDate();
        // console.log(typeof month, typeof day);
        if (month < 10) {
          month = "0" + month;
        }
        if (day < 10) {
          day = "0" + day;
        }
        //变成String类型了
        var uniqueNo = carNo + month + day;
        console.log(uniqueNo);

        //拿产品
        var storageDetails = new Array();
        var hang = tableView.purchaseDetailsenterStorage.children().find("tr")
          .length;
        // var lie = tableView.purchaseDetailsenterStorage
        //   .children()
        //   .find("tr")
        //   .find("td").length;
        var td = tableView.purchaseDetailsenterStorage
          .children()
          .find("tr")
          .find("td");
        console.log(hang);
        for (var j = 1; j < hang; j++) {
          var temp = {
            number, //数字类型
            position: "",
            product: {
              productNo
            },
            uniqueNo: ""
          };
          var productNo;
          temp.number = parseInt(td.eq(1).html());
          temp.position = position; //这里不知道哪里拿---->输入
          temp.product.productNo = parseInt(td.eq(3).html());
          temp.uniqueNo = uniqueNo + j;
          storageDetails.push(temp);
        }
        var dataTest = {
          carNo: carNo,
          date: date,
          employeeNo: employeeNo,
          orderNo: orderNo,
          storageDetails: storageDetails,
          type: parseInt(type66)
        };
        console.log(JSON.stringify(dataTest));
        //执行进仓单添加
        $.ajax({
          url: "http://www.fjemiot.cn/erp/enterStorage",
          type: "post",
          data: JSON.stringify(dataTest),
          // contentType: "text/plain",
          contentType: "application/json",

          success: reply => {
            console.log(reply);
            tip.alert("添加成功", "进仓主表", "success", 1500);
          },
          error: reply => {
            tip.alert("添加失败", "进仓主表", "error", 1500);
          }
        });
      });
    });
    //点击查看，对选中的进仓详细进行删除操作
    $(".detailsenterStorage-view").on("click", "tr", function() {
      // console.log($(this).index());//当前点击的行数
      // 弹框
      // $(".detailsEditenterStorage")
      //   .removeClass("hide")
      //   .addClass("show");
      //显示选中
      $(".select-tr").removeClass("select-tr"); //这个没有用不知道为什么
      $(this).addClass("select-tr"); //加上背景色
      //赋值
      var number = $(this)
        .find("td")
        .eq(3)
        .html();
      var position = $(this)
        .find("td")
        .eq(1)
        .html();
      var uniqueNo = $(this)
        .find("td")
        .eq(2)
        .html();

      $(".detailsEditenterStorage .i1501").val(number); //赋值给车号
      $(".detailsEditenterStorage .i1502").val(position); //赋值给日期
      $(".detailsEditenterStorage .i1503").val(uniqueNo); //赋值给验货员

      // var tr = this;
      // $(".select-tr").removeClass("select-tr"); //这个没有用不知道为什么
      // $(this).addClass("select-tr"); //加上背景色
      var tr = tableView.detailsenterStorage.children().find("tr"); //找到很多的tr
      //一个一个push进去
      var detailsenterStorageTable = new Array();
      for (var i = 1; i < tr.length; i++) {
        var td = $(tr[i]).find("td");
        const temp = {
          orderNo: "",
          number: "",
          price: "",
          productNo: "",
          brand: "",
          type: "",
          gWeight: "",
          standard: "",
          level: "",
          unit: "",
          cost: ""
        };
        temp.orderNo = td.eq(0).html();
        temp.number = td.eq(1).html();
        temp.price = td.eq(2).html();
        temp.productNo = td.eq(3).html();
        temp.brand = td.eq(4).html();
        temp.type = td.eq(5).html();
        temp.gWeight = td.eq(6).html();
        temp.standard = td.eq(7).html();
        temp.level = td.eq(8).html();
        temp.unit = td.eq(9).html();
        temp.cost = td.eq(10).html();
        if (i != $(this).index()) {
          detailsenterStorageTable.push(temp);
        }
      }
      console.log(detailsenterStorageTable);
      //点击删除
      $(".detailsenterStorage .detailsenterStorage-del").on(
        "click",
        function() {
          //使用接口删除。重新展示数据
          //执行进仓明细表的单条商品删除
          var td = tableView.MasterenterStorage.children().find("tr");
          var td2 = tableView.detailsenterStorage.children().find("tr");
          var entryStorageNo = td
            .find("td")
            .eq(6)
            .html();
          var productNo = td2
            .find("td")
            .eq(4)
            .html();
          console.log("8888");
          // console.log(entryStorageNo);
          console.log(productNo);
          if (typeof productNo != undefined) {
            $.ajax({
              url:
                "http://www.fjemiot.cn/erp/enterStorageDetail/" +
                entryStorageNo +
                "/" +
                productNo,
              type: "delete",
              contentType: "text/plain",
              success: reply => {
                console.log(reply);
                tip.alert("删除成功", "单条进仓明细表", "success", 1500);
              },
              error: reply => {
                tip.alert("删除失败", "单条进仓明细表", "error", 1500);
              }
            });
          } else {
            tip.alert("选择单条产品才能删除", "警告", "warn");
          }
          //获得当前的进仓单的详细表格、重新赋值
          tableView.detailsenterStorage.html(
            tablegen(detailsenterStorageTable)
          );
          tableView.detailsenterStorage.html(tablegen());
        }
      );
    });
  });

  //purchase
  $.ajax({
    url:
      "http://www.fjemiot.cn/erp/enterStorage?pageNum=" +
      page +
      "&pageSize=5&type=0",
    success: reply => {
      tableView.enterStorage.append(tablegen(reply.value));
      console.log(reply.value);
      typeTest = reply.value[0].type;
      console.log("type" + typeTest);
    },
    error: reply => {
      tip.alert("获取信息失败", "采购订单列表", "error", 1500);
    }
  });
  // 采购主表
  $.ajax({
    url: "http://www.fjemiot.cn/erp/purchase?pageNum=1&pageSize=20",
    success: reply => {
      for (var i = 0; i < reply.value.length; i++) {
        delete reply.value[i].purchaseDetails;
      }
      tableView.purchase.append(tablegen(reply.value));
      console.log(reply.value);
    },
    error: reply => {
      tip.alert("获取信息失败", "采购订单列表", "error", 1500);
    }
  });
});
